package com.bodgittandscarper.broker.types;

import com.bodgittandscarper.broker.types.impl.DatabaseFieldImpl;
import com.bodgittandscarper.broker.types.impl.DatabaseSchemeImpl;
import com.bodgittandscarper.broker.types.impl.RecordImpl;

/**
 * Factory class for obtaining instances of database related entity types. 
 * All types should be created through this factory. 
 * 
 * @author Morten Rummelhoff
 *
 */
public final class TypeFactory {
	
	//Singleton implementation
	private static TypeFactory instance = new TypeFactory();
	
	//private constructor for avoiding unintentionally instantiation of class
	private TypeFactory() {	
	}
	
	/**
	 * Creates a <code>RecordMod</code> that represents a database record. This method is to be used internally in the Server
	 * Application.
	 * 
	 * @param recNo specifies the recNo. Must be a valid non-used number. 
	 * @param isValid specifies if this record should be valid or not. Normally new records are valid.
	 * @param isLocked specifies if the record is locked. Normally new records are unlocked.
	 * @param fields the contents of the record. I.E. the field data.
	 * @return a <code>RecordMod</code> containing the provided data and ready to use.  
	 */
	public RecordMod createRecordMod(int recNo, boolean isValid, boolean isLocked, String[] fields) {
		return new RecordImpl(recNo, isValid, isLocked, fields);
	}
	
	/**
	 * Creates an empty <code>DatabaseScheme</code>. Method is used purely for the Server Application. 
	 * 
	 * @return a DatabaseScheme object to be used for holding the database field information.
	 */
	public DatabaseSchemaMod createDatabaseSchemeMod() {
		return new DatabaseSchemeImpl();
	}
	
	/**
	 * Creates a <code>DatabaseField</code> holding information about a database field name and size.
	 * Method is used only in the Server Application.
	 * 
	 * @param fieldName specifies the name of the field
	 * @param fieldSize specifies the size of the field
	 * @return a <code>DatabaseField</code> with the specified name and size.
	 */
	public DatabaseField createDatabaseField(String fieldName, int fieldSize) {
		return new DatabaseFieldImpl(fieldName, fieldSize);
	}
	
	/**
	 * Gets the TypeFactory instance. The factory class provides various kinds of methods for creating database elements. 
	 * 
	 * @return singleton reference of the <code>TypeFactory</code> instance
	 */
	public static TypeFactory getInstance() {
		return instance;
	}
	
	
}
